-- local skynet = require "skynet"
-- local protobuf = require "protobuf" --引入文件protobuf.lua

-- skynet.start(function()
--     protobuf.register_file "./protos/test.pb"
--     skynet.error("protobuf register: test.pb")

--     local stringbuffer = protobuf.encode("cs.test", --对应person.proto协议的包名与类名
--     {
--         name = "xiaoming",
--         age = 1,
--         email = "xiaoming@163.com",
--         online = true,
--         account = 888.88,
--     })

--     local data = protobuf.decode("cs.test",stringbuffer)
--     skynet.error("------decode------ \nname=",data.name
--         , ",\nage=", data.age
--         , ",\nemail=", data.email
--         , ",\nonline=", data.online
--         , ",\naccount=", data.account)
-- end)


local skynet = require "skynet"
local protobuf = require "protobuf" --引入文件protobuf.lua

skynet.start(function()
    protobuf.register_file "./protos/person.pb"
    skynet.error("protobuf register：person.pb")

    local stringbuffer = protobuf.encode("cs.Person", --对应person.proto协议的包名与类名
    {
        name = "xiaoming",
        id = 1,
        email = "xiaoming@163.com",
        phone = {
                    {
                        number = "1388888888",
                        type = "MOBILE",
                    },
                    {
                        number = "8888888",
                    },
                    {
                        number = "87878787",
                        type = "WORK",
                    },

                }
    })

    local data = protobuf.decode("cs.Person",stringbuffer)
    skynet.error("decode name="..data.name..",id="..data.id..",email="..data.email)
    skynet.error("decode phone.type="..data.phone[1].type..",phone.number="..data.phone[1].number)
    skynet.error("decode phone.type="..data.phone[2].type..",phone.number="..data.phone[2].number)
    skynet.error("decode phone.type="..data.phone[3].type..",phone.number="..data.phone[3].number)
end)


